package com.nbjtjc.safe.service.danger;

import cn.hutool.core.collection.CollectionUtil;
import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.safe.bean.Constant;
import com.nbjtjc.safe.bean.MyCache;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.danger.DangerReformReplyMapper;
import com.nbjtjc.safe.model.danger.DangerReformReply;
import com.nbjtjc.safe.util.MyShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/6/23 10:56
 **/
@Service
public class DangerReformReplyService {

    @Autowired
    private DangerReformReplyMapper dangerReformReplyMapper;

    @Autowired
    private MyCache myCache;
    public DangerReformReply add(DangerReformReply dangerReformReply){
        dangerReformReply.setUserId(MyShiroUtils.getSessionUserId());
        dangerReformReplyMapper.insertSelective(dangerReformReply);
        return dangerReformReply;
    }

    public List<DangerReformReply> find(DangerReformReply dangerReformReply){
        List<DangerReformReply> dangerReformReplies=new ArrayList<>();
        dangerReformReplies=dangerReformReplyMapper.search(dangerReformReply);
        if(CollectionUtil.isNotEmpty(dangerReformReplies)){
            dangerReformReplies.parallelStream().forEach(dangerReformReply1 -> {
                dangerReformReply1.setUserName(myCache.getUserName(dangerReformReply1.getUserId()));
            });
        }
        return dangerReformReplies;
    }

    public DangerReformReply update(DangerReformReply dangerReformReply){
        dangerReformReplyMapper.updateByPrimaryKeySelective(dangerReformReply);
        return dangerReformReply;
    }

}
